package com.example.geguo.nettyclientchatdemo.bean;

import com.google.gson.Gson;
import com.thoughtworks.xstream.XStream;

//强大 的对象 与 xml ,json
public class ProtocalObj {
	public String toXml() {
		// 创建核心类
		XStream x = new XStream();
		x.alias(getClass().getSimpleName(), getClass());
		// 调用toxml
		String xml = x.toXML(this);
		return xml;
	}
	public Object fromXml(String xml) {
		// 创建核心类
		XStream x = new XStream();
		x.alias(getClass().getSimpleName(), getClass());
		// 调用toxml
		return x.fromXML(xml);
	}
	public String toJson() {
		Gson gson=new Gson();
		return gson.toJson(this);
	}
	public Object fromJson(String json) {
		Gson gson=new Gson();
		return gson.fromJson(json, getClass());
	}
}
